package com.web;

import com.pojo.Book;
import com.pojo.Page;
import com.service.BookService;
import com.service.impl.BookServiceImpl;
import com.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClientBookServlet extends BaseServlet{
        private BookService bookService = new BookServiceImpl();
        protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            int pageNo = WebUtils.parseInt(req.getParameter("pageNo"),1);
            int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
            Page<Book> page = bookService.page(pageNo,pageSize);
            page.setUrl("client/bookServlet?action=page");
            System.out.println(page.getUrl());
            req.setAttribute("page",page);
            req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);
        }
        protected void pageByPrice(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            int pageNo = WebUtils.parseInt(req.getParameter("pageNo"),1);
            int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
            int min=WebUtils.parseInt(req.getParameter("min"),0);
            int max=WebUtils.parseInt(req.getParameter("max"),9999999);
            Page<Book> page=bookService.pageByPrice(pageNo,pageSize,min,max);
            page.setUrl("client/bookServlet?action=pageByPrice");
            req.setAttribute("page",page);
           //req.setAttribute("min",min);
           // req.setAttribute("max",max);
            req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);
        }
}
